#构造_init__和new方法
# class Student:
#
#     def __init__(self,name,score):
#         self.name=name
#         self.score=score
#
#     def say_score(self):
#         print("{0}的分数是{1}".format(self.name,self.score))
#
#
# s1 = Student("张三",30)
# print(s1.name,s1.score)
# s1.say_score()
#
# s2=Student("李四",45)
# s2.say_score()
# print(s2.name,s2.score)


# #实例属性_内存分析
# class Student:
#     def __init__(self,name,score):   self相当于java中的this语句
#         self.name=name     新增name属性
#         self.score=score   新增score属性
#
#
#     def say_score(self):
#         self.age=18                          新增age属性
#         print("{0}的分数是{1}".format(self.name,self.score))
#
#
# s1=Student("张三",80)
# s1.say_score()
# print(s1.name,s1.score,s1.age)
#
# s2=Student("冠宇",88)
# s2.address="上海市南京路"
# print(s2.address)



#内存分析方法调用过程_dir()_isinstance
# class Student:
#     def __init__(self,name,score):
#         self.name=name
#         self.score=score
#
#     def say_score(self):
#         self.age=18
#         print("{0}的分数是{1}".format(self.name,self.score))
#
# s1=Student("冠宇",99)
# s1.say_score()
# print(dir(s1)) #获得所有属性与方法打印出来
# print(s1.__dict__)#返回对象的所有属性
# print(isinstance(s1,Student)) #确定是不是需要的对象与属性,返回的是布尔值

#
# class Student:
#     pass
#
#
# class Car:
#     pass
#
# print(type(Student))
# print(id(Student))
#
# print(id(Car))




#内存分析实例对象和类对象的创建过程
# class Student:
#     company="阿里巴巴" #类属性
#     count=0
#
#
#     def __init__(self,name,score):
#         self.name=name     #属性实例化
#         self.score=score
#         Student.count=Student.count+1
#
#     def say_score(self):  #实例方法
#         print("我的公司是：",Student.company)
#         print(self.name,'的分数是:',self.score)
#
# s1=Student("冠宇",100) #创建了对象
# s2=Student("子丫",99)  #第二个对象
# s1.say_score()
# s2.say_score()
# print("一共创建了{0}个对象".format(Student.count))


#类方法与静态方法
# class Student:
#     company="SXT" #类属性
#
#
#     def __init__(self,name,score):
#         self.name=name  #属性实例化
#     @classmethod
#     def printCompany(cls):
#         print(cls.company)
#
#
#     @staticmethod
#     def add(a,b):
#         print("{0}+{1}={2}".format(a,b,a+b))
#         return a+b
#
#
# Student.printCompany()
# Student.add(100,200)


#析构函数与垃圾回收机制
# class Person:
#     def __init__(self):
#         print("销毁对象：{0}".format(self))
#
# p1=Person()
# p2=Person()
# del p2 #回收
# print("程序结束")




#call方法和可调用对象
# def f1():
#     print("f1")
# f1()
#
#
# class Car:
#     def __call__(self,age,money):
#         print("call方法")
#         print("车龄{0},金额{1}".format(age,money))
#
# c=Car()
# c(3,2000000)


#方法没有重载_方法的动态性 /python中方法没有重载
# class Person:
#
#     def say_hi(self):
#         print("hello")
#
#     def say_hi(self,name):
#         print("{0},hello".format(name))
#
# p1=Person()
# p1.say_hi("高淇")


# class Person:
#     def work(self):
#         print("努力工作!")
#
#
# def play_game(s):
#     print("玩游戏")
#
#
# def work2(s):
#     print("好好工作,努力工作!")
#
#
# Person.play=play_game  #把原来类中的方法修改了
# Person.work=work2
#
# p=Person()
# p.play()
# p.work()


#私有属性与私有方法(实现封装)
# #测试私有属性与方法:
# class Employee:
#    __company="百战程序员"  #__成员变量就无法进行访问
#
#     def __init__(self,name,age):
#         self.name=name
#         self.age=age
#
#     def say_company(self):
#         print("我的公司是：",Employee.__company)
#
#
# print(dir(Employee))
# print(Employee._Employee__company)
# a=Employee("高其",19)
# print(a.age)


#@property装饰器：将方法的调用变成属性调用
# class Employee:
#
#     def __init__(self,name,salary):
#         self.name=name
#         self.__salary=salary
#
#     @property
#     def salary(self):
#         print("薪资是:",self.__salary)
#         return self.__salary
#
#     @salary.setter
#     def salary(self,salary):
#         if 0<salary<1000000:
#             self.__salary=salary
#         else:
#             print("薪资输入错误!只能在0-100000之间")
#
# emp1=Employee("冠宇",200000)
# print(emp1.name,emp1.salary)


#None对象的特殊性
#
# obj=None
# obj2=None
# print(id(obj))
# print(id(obj2))
# print(type(obj))

#面向对象的三大特征：(封装, 继承, 多态)
# class Student:
#     pass
#
# class Car:   #父类是object
#     pass
#
# class Bwm(Car):  #Bwm-->Car-->object
#     pass

# class Person:    #实际上是我们可以继承父类中的成员变量进行使用，也可以在子类的成员变量中也可以定义并进行使用,减少了代码量
#     def __init__(self,name,age):
#         print("创造Person")
#         self.name=name   #相当于java中的this语句,先构造父类
#         self.age=age
#     def say_age(self):
#         print("{0}的年龄是{1}".format(self.name,self.age))
#
# class Studet(Person):
#     def __init__(self,name,age,score):
#
#         # Person.__init__(self, name, age)  #两个调用构造方法的方式都可以
#         super(Studet,self).__init__(name,age)  #调用父类的构造方法
#         print("创建Student")
#         self.score=score
#
#     def say_score(self):
#         print(self.name+"的分数是:",self.score)
#
#     def say_name(self):   #重写父类的方法
#         print("报告老师,我是"+self.name)
#
# s1=Studet("冠宇",18,90)
# s1.say_age() #调用放在最下面
# s1.say_score()
# s1.say_name()


# #查看类的继承层次结构
# class A:pass
# class B(A):pass
# class C(B):pass
# print(C.mro())
# obj=object()

# class A:
#     def aa(self):
#         print("aa")
#     def bb(self):
#         print("bb")
# class C(B,A):
#     def cc(self):
#         print("cc")
#
# c=C()
# c.cc()
# c.bb()
# c.aa()

# #super()获得父亲的定义
# class A:
#     def __init__(self):
#         print("A的构造方法")
#
#     def say(self):
#         print("A:",self)
#         print("say:AAA")
#
# class B(A):
#     def __init__(self):
#         A.__init__() #这个也可以调用A的构造方法
#         super(B,self).__init__() #调用父类的构造方法
#         print("B的构造方法")
#
#     def say(self):
#         A.say(self) #也可以用这个调用
#         #super().say() #通过super调用父类的方法
#         print("say BBB")
#
# b=B() #B继承了父类A()
# b.say() #调用时会打印父类A的方法和子类B的方法


#多态详解 :猫与狗均属于动物但是不同动物有不一样的行为,这个就可以抽象为多态
# class Animai():
#     def shout(self):
#         print("动物叫了一声")
#
# class Dog(Animai):
#     def shout(self):
#         print("狗叫了一声")
#
# class Cat(Animai):
#     def shout(self):
#         print("猫叫了一声")
#
# def animalShout(a):
#     a.shout()  #将方法调用进来
#
# animalShout(Dog())
# animalShout(Cat())

#特殊方法与运算符重载
# a=20
# b=30
# c=a+b
# d=a.__add__(b)
# print(d)
# print(c)


# import copy
# #浅拷贝与深拷贝内存对象分析
# class MobilPhone():
#     def __init__(self,cpu):
#         self.cpu=cpu
#
# class CPU:
#     pass
#
# c=CPU()
# m=MobilPhone(c)
#
# print("浅拷贝------")
# m2=copy.copy(m)#将m2是m对象的一个拷贝对象
# print(id(m))

#继承与组合
# class CPU:
#     def calulate(self):
#         print("正在计算,算个12345!")
#
# class Screen:
#     def show(self):
#         print("显示一个更好看的画面,亮瞎你的眼")
#
# class MobilPhone(CPU,Screen):
#     def __init__(self,cpu,screen):
#         self.cpu=cpu
#         self.screen=screen
#
# c=CPU()
# s=Screen()
# m=MobilPhone(c,s)
# m.cpu.calulate()
# m.screen.show()

#设计模式_工厂模式的实现
# class Benz:pass
# class BMW:pass
# class AoDi:pass
#
# class CarFactory:
#     def createCar(self,brand):
#         if brand=="奔驰":
#             return Benz()
#         elif brand=="宝马":
#             return BMW()
#         elif brand=="奥迪":
#             return AoDi()
#         else:
#             return "未知品牌,无法创造"
#
# factory=CarFactory()
# c1=factory.createCar("奔驰")
# c2=factory.createCar("宝马")
# print(c1)
# print(c2)

